package cel;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.snapshot.RobotState;
import robocode.control.testing.RobotTestBed;

/**
 * Tests that WayFarer moves to any wall during a battle.
 * 
 * @author Elmar Carillo
 */
public class TestWayFarerHitWall extends RobotTestBed {
  /** True if the robot hit a wall during the test case. */
  boolean hitWall = false;

  /**
   * Specifies that SittingDuck and WayFarer are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,cel.WayFarer";
  }

  /**
   * This test runs for 10 round.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * After each turn, check to see if hit a wall.
   * 
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    // Get the snapshot of the robot daCruzer
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];

    // Checks to see if the robot visited a wall
    RobotState robotState = robot.getState();
    if (robotState.isHitWall()) {
      hitWall = true;
    }
  }

  /**
   * After the battle, check to see if the robot hit a wall.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check HitWall", hitWall);
  }
}
